/******************************************************************************* 
 *  Copyright 2007 Amazon Technologies, Inc.  
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  
 *  You may not use this file except in compliance with the License. 
 *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 *  specific language governing permissions and limitations under the License.
 * ***************************************************************************** 
 *    __  _    _  ___ 
 *   (  )( \/\/ )/ __)
 *   /__\ \    / \__ \
 *  (_)(_) \/\/  (___/
 * 
 *  Amazon ECS CSharp Library
 *  API Version: 2007-07-16
 *  Generated: Thu Aug 02 10:15:38 PDT 2007 
 * 
 */

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Text;


namespace Amazon.ECS.Model
{
    [XmlTypeAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16")]
    [XmlRootAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16", IsNullable = false)]
    public class CustomerReviews
    {
    
        private Decimal? averageRatingField;

        private Decimal? totalReviewsField;

        private Decimal? totalReviewPagesField;

        private  List<Review> reviewField;


        /// <summary>
        /// Gets and sets the AverageRating property.
        /// </summary>
        [XmlElementAttribute(ElementName = "AverageRating")]
        public Decimal AverageRating
        {
            get { return this.averageRatingField.GetValueOrDefault() ; }
            set { this.averageRatingField= value; }
        }



        /// <summary>
        /// Sets the AverageRating property
        /// </summary>
        /// <param name="averageRating">AverageRating property</param>
        /// <returns>this instance</returns>
        public CustomerReviews WithAverageRating(Decimal averageRating)
        {
            this.averageRatingField = averageRating;
            return this;
        }



        /// <summary>
        /// Checks if AverageRating property is set
        /// </summary>
        /// <returns>true if AverageRating property is set</returns>
        public Boolean IsSetAverageRating()
        {
            return  this.averageRatingField != null;

        }


        /// <summary>
        /// Gets and sets the TotalReviews property.
        /// </summary>
        [XmlElementAttribute(ElementName = "TotalReviews")]
        public Decimal TotalReviews
        {
            get { return this.totalReviewsField.GetValueOrDefault() ; }
            set { this.totalReviewsField= value; }
        }



        /// <summary>
        /// Sets the TotalReviews property
        /// </summary>
        /// <param name="totalReviews">TotalReviews property</param>
        /// <returns>this instance</returns>
        public CustomerReviews WithTotalReviews(Decimal totalReviews)
        {
            this.totalReviewsField = totalReviews;
            return this;
        }



        /// <summary>
        /// Checks if TotalReviews property is set
        /// </summary>
        /// <returns>true if TotalReviews property is set</returns>
        public Boolean IsSetTotalReviews()
        {
            return  this.totalReviewsField != null;

        }


        /// <summary>
        /// Gets and sets the TotalReviewPages property.
        /// </summary>
        [XmlElementAttribute(ElementName = "TotalReviewPages")]
        public Decimal TotalReviewPages
        {
            get { return this.totalReviewPagesField.GetValueOrDefault() ; }
            set { this.totalReviewPagesField= value; }
        }



        /// <summary>
        /// Sets the TotalReviewPages property
        /// </summary>
        /// <param name="totalReviewPages">TotalReviewPages property</param>
        /// <returns>this instance</returns>
        public CustomerReviews WithTotalReviewPages(Decimal totalReviewPages)
        {
            this.totalReviewPagesField = totalReviewPages;
            return this;
        }



        /// <summary>
        /// Checks if TotalReviewPages property is set
        /// </summary>
        /// <returns>true if TotalReviewPages property is set</returns>
        public Boolean IsSetTotalReviewPages()
        {
            return  this.totalReviewPagesField != null;

        }


        /// <summary>
        /// Gets and sets the Review property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Review")]
        public List<Review> Review
        {
            get
            {
                if (this.reviewField == null)
                {
                    this.reviewField = new List<Review>();
                }
                return this.reviewField;
            }
            set { this.reviewField =  value; }
        }



        /// <summary>
        /// Sets the Review property
        /// </summary>
        /// <param name="list">Review property</param>
        /// <returns>this instance</returns>
        public CustomerReviews WithReview(params Review[] list)
        {
            foreach (Review item in list)
            {
                Review.Add(item);
            }
            return this;
        }          
 


        /// <summary>
        /// Checks if Review property is set
        /// </summary>
        /// <returns>true if Review property is set</returns>
        public Boolean IsSetReview()
        {
            return (Review.Count > 0);
        }




        /// <summary>
        /// XML fragment representation of this object
        /// </summary>
        /// <returns>XML fragment for this object.</returns>
        /// <remarks>
        /// Name for outer tag expected to be set by calling method. 
        /// This fragment returns inner properties representation only
        /// </remarks>


        protected internal String ToXMLFragment() {
            StringBuilder xml = new StringBuilder();
            if (IsSetAverageRating()) {
                xml.Append("<AverageRating>");
                xml.Append(this.AverageRating);
                xml.Append("</AverageRating>");
            }
            if (IsSetTotalReviews()) {
                xml.Append("<TotalReviews>");
                xml.Append(this.TotalReviews);
                xml.Append("</TotalReviews>");
            }
            if (IsSetTotalReviewPages()) {
                xml.Append("<TotalReviewPages>");
                xml.Append(this.TotalReviewPages);
                xml.Append("</TotalReviewPages>");
            }
            List<Review> reviewList = this.Review;
            foreach (Review review in reviewList) {
                xml.Append("<Review>");
                xml.Append(review.ToXMLFragment());
                xml.Append("</Review>");
            }
            return xml.ToString();
        }

        /**
         * 
         * Escape XML special characters
         */
        private String EscapeXML(String str) {
            StringBuilder sb = new StringBuilder();
            foreach (Char c in str)
            {
                switch (c) {
                case '&':
                    sb.Append("&amp;");
                    break;
                case '<':
                    sb.Append("&lt;");
                    break;
                case '>':
                    sb.Append("&gt;");
                    break;
                case '\'':
                    sb.Append("&#039;");
                    break;
                case '"':
                    sb.Append("&quot;");
                    break;
                default:
                    sb.Append(c);
                    break;
                }
            }
            return sb.ToString();
        }




    }

}